<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>弹幕</title>
     <script src="./js/jquery-3.7.1.min.js"></script>

    <style>
        *{
            margin:0;
            padding:0;

        }
        body{
              height: 100vh;
            width: 100%;
              background: url('http://sprs.dingplayer.com/assets/userbg.png') no-repeat;
              background-size: 100% 100%;
        }
    </style>
</head>
<body>
    <div>
        请点击“使用完整服务”以后重新扫码进入
    </div>
    <script>

        var url = window.location.href;

        // 使用URLSearchParams来解析URL中的参数
        var params = new URLSearchParams(url.split('?')[1]);

        // 获取code参数的值
        var code = params.get('code');

        function iso88591ToUtf8(isoString) {
            // 将ISO-8859-1字符串转换为Uint8Array字节数组
            var isoChars = isoString.split('').map(function(c) {
                return c.charCodeAt(0);
            });
            var isoBytes = new Uint8Array(isoChars);

            // 将Uint8Array字节数组转换为UTF-8字符串
            var utfString = new TextDecoder('utf-8').decode(isoBytes);

            return utfString;
            }
        $.ajax({
           url: `/api/getUserinfo?code=${code}`,
            method:'GET',
            contentType:'application/json',
            success:function(res){
                if(res.openid){
                    window.location.href = `${window.location.origin}/user.html?nickname=${iso88591ToUtf8(res.nickname)}&headimgurl=${res.headimgurl}&openid=${res.openid}`;
                }
                // window.location.href = `https://sprs001-1gbgyhy7fb221c6e-1332321237.tcloudbaseapp.com?nickname=${iso88591ToUtf8(res.nickname)}&headimgurl=${res.headimgurl}`;
                // window.location.href = `${window.location.origin}/user.html?nickname=${iso88591ToUtf8(res.nickname)}&headimgurl=${res.headimgurl}&openid=${res.openid}`;
            },
            error:function(err){

            }
        })

    </script>
</body>
</html>